//package com.example.demo.config;
//
//import com.Reader;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//    @Autowired
//    private ReaderRepository readerRepository;
//
//    protected void configure(HttpSecurity http) throws Exception{
//        http.authorizeRequests().antMatchers("/").access("hasRole('REAEER')").antMatchers("/**").permitAll()
//                .and()
//                .formLogin().loginPage("/login").failureUrl("/login?error=true");
//    }
//    @Override
//    protected void configure(
//            AuthenticationManagerBuilder auth) throws Exception {
//        auth
//                .userDetailsService(new UserDetailsService() {
//                    @Override
//                    public UserDetails loadUserByUsername(String username)
//                            throws UsernameNotFoundException {
//                        return (Reader)(readerRepository.findById(username).get());
//                    }
//                });
//    }
//}
